﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using WebServer.DBUtility;
using WebServer.Models;

namespace WebServer.DBAccess
{
    public class WebConfigurationDA
    {
        #region 网站设置：查询，修改

        /// <summary>
        /// 网站配置
        /// </summary>
        /// <param name="Fn">True-更新缓存，False-缓存</param>
        /// <param name="Show">0-全部显示</param>
        /// <returns></returns>
        public WebConfiguration WebConfigurationInfo(int Show = 0)
        {
            WebConfiguration entity = new WebConfiguration();
            try
            {
                SQLHelper sqlHelp = new SQLHelper();
                using (IDataReader reader = sqlHelp.ExecuteReader("[sp_W_WebConfiguration_Q]"))
                {
                    while (reader.Read())
                    {

                        if (reader[0] != DBNull.Value)
                            entity.ID = reader[0].ToInt32();
                        else
                            entity.ID = 0;
                        entity.WebLogo = reader[1].ToString();
                        entity.WebName = reader[2].ToString();
                        entity.CompanyName = reader[3].ToString();
                        entity.CompanyAddress = reader[4].ToString();
                        entity.CompanyZip = reader[5].ToString();
                        entity.CompanyPeo = reader[6].ToString();
                        entity.CompanyMobile = reader[7].ToString();
                        entity.CompanyTel = reader[8].ToString();
                        entity.CompanyFax = reader[9].ToString();
                        entity.CompanyEmail = reader[10].ToString();
                        entity.CompanyICP = reader[11].ToString();
                        entity.CompanyQQ = reader[12].ToString();
                        entity.CompanyWechat = reader[13].ToString();
                        entity.CompanyWechatImg = reader[14].ToString();
                        entity.Keywords = reader[15].ToString();
                        entity.Description = reader[16].ToString();
                        if (reader[17] != DBNull.Value)
                            entity.WebClose = reader[17].ToBoolean();
                        else
                            entity.WebClose = false;
                        entity.WebDescription = reader[18].ToString();
                        entity.WebApp = reader[19].ToString();
                        if (reader[20] != DBNull.Value)
                            entity.CreateTime = reader[20].ToDateTime();
                        else
                            entity.CreateTime = DateTime.Now;
                        entity.ShareLogo = reader[21].ToString();
                        if (Show == 0)
                        {
                            entity.BlockKey = reader[22].ToString();
                        }
                        if (reader[23] != DBNull.Value)
                            entity.IsApple = reader[23].ToBoolean();
                        else
                            entity.IsApple = false;
                        if (reader[24] != DBNull.Value)
                            entity.IsAndroid = reader[24].ToBoolean();
                        else
                            entity.IsAndroid = false;

                    }
                    reader.Close();
                }
            }
            catch (Exception ex)
            {
            }
            return entity;
        }



        /// <summary>
        /// 修改网站配置
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int UWebConfiguration(WebConfiguration entity)
        {
            try
            {
                object[] WhereInfo = new object[] { entity.ID,entity.WebLogo,entity.WebName,entity.CompanyName,entity.CompanyAddress,entity.CompanyZip,entity.CompanyPeo,entity.CompanyMobile,entity.CompanyTel,entity.CompanyFax,entity.CompanyEmail,entity.CompanyICP,entity.CompanyQQ,entity.CompanyWechat,entity.CompanyWechatImg,entity.Keywords,entity.Description,entity.WebClose,entity.WebDescription,entity.WebApp,entity.BlockKey,entity.IsApple,entity.IsAndroid};
                SQLHelper sqlHelp = new SQLHelper();
                object obj = sqlHelp.ExecuteSPScalar("[sp_W_WebConfiguration_Set]", WhereInfo);
                if (obj != null && obj != DBNull.Value)
                {
                    return Convert.ToInt32(obj);
                }
                else
                    return 0;
            }
            catch (Exception ex)
            {
                return 0;
            }
        }

        #endregion
    }
}
